<template>
  <div>
    <div class="logo-wrapper">
      <img class="logo" src="../../assets/logo.png">
    </div>
    <group title="管理员登陆" class="weui-cells_form">
      <x-input title="邮箱" name="email" placeholder="请输入邮箱地址" is-type="email"></x-input>
      <x-input title="密码" name="password" placeholder="请输入密码" type="password" @on-enter="onEnter"></x-input>
      <!-- <x-input title="验证码" class="weui-cell_vcode">
        <img slot="right" class="weui-vcode-img" src="http://weui.github.io/weui/images/vcode.jpg">
      </x-input> -->
      <!-- <x-input title="验证码" class="weui-cell_vcode">
        <img slot="right" class="weui-vcode-img" src="http://weui.github.io/weui/images/vcode.jpg">
      </x-input> -->
      <!-- <x-input title="发送验证码" class="weui-vcode">
        <x-button slot="right" type="primary" mini>发送验证码</x-button>
      </x-input> -->
    </group>
    <box gap="10px 10px">
      <x-button type="primary" @click.native="onLoginClick">登录</x-button>
    </box>
  </div>
</template>

<script>
import { XInput, Group, XButton, Cell, Box } from 'vux'

export default {
  components: {
    XInput,
    XButton,
    Group,
    Cell,
    Box
  },
  data () {
    return {

    }
  },
  methods: {
    getValid1 () {
      this.valid1 = this.$refs.input01.valid
    },
    getValid2 () {
      this.valid2 = this.$refs.input02.valid
    },
    change (val) {
      console.log(val)
    },
    onBlur (val) {
      console.log('on blur', val)
    },
    onFocus (val, $event) {
      console.log('on focus', val, $event)
    },
    onEnter (val) {
      this.onLoginClick()
    },
    onLoginClick() {
      //this.$router.replace('/') 
      


      var username = document.querySelectorAll(".weui-input")[0].value;
      var password = document.querySelectorAll(".weui-input")[1].value;
      console.log("邮箱-->" + username);
      console.log("密码-->" + password);

      // if (username = undefined) {
      //   this.$vux.toast.text('请输入用户名', 'middle');   
      // }
      // if (username == "" && password == "") {
      //   alert('用户名或密码不能为空');
      // }


      // if (username == 110801010004 && password == 112235) {
        //创建对象
        var xhr = new XMLHttpRequest();
        //建立连接
        xhr.open("post", "index.php/login/doLogin");
        //post方式必须的请求头
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");  
        //接收数据
        xhr.onreadystatechange=function() {
          if(xhr.readyState == 4 && xhr.status == 200) {
            var data = xhr.responseText;
            //var obj = eval('('+data+')');
            var obj = JSON.parse(data);
            console.log(obj);
          } 
        };
        //发送数据
        xhr.send("username=" + username + "&password=" + password); 
        if (username == 110801010004 && password == 112235) {
          location.href="/";
        } else if (username == "" || password == "") {
          this.$vux.toast.text('用户名或密码不能为空', 'middle'); 
        } else if (username != 110801010004 && password != "") {
          this.$vux.toast.text('您填写用户不存在', 'middle');
        } else if (password != 112235 && password != "") {
          this.$vux.toast.text('您填写的密码不正确', 'middle');
        }

        
      // };


      // if (username == "" || password == "") {
      //   //创建对象
      //   var xhr = new XMLHttpRequest();
      //   //建立连接
      //   xhr.open("post", "index.php/login/doLogin");
      //   //post方式必须的请求头
      //   xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");  
      //   //接收数据
      //   xhr.onreadystatechange=function() {
      //     if(xhr.readyState == 4 && xhr.status == 200) {
      //       var data = xhr.responseText;
      //       //var obj = eval('('+data+')');
      //       var obj = JSON.parse(data);
      //       console.log(obj);
      //       // console.log(obj.code);
      //       // console.log(obj.msg);
      //       //location.href = "/";
      //     } 
      //   };
      //   //发送数据
      //   xhr.send("username=" + username + "&password=" + password); 
      //   this.$vux.toast.text('用户名或密码不能为空', 'middle');          
      // };


      // if (password != 112235 && password != "") {
      //   //创建对象
      //   var xhr = new XMLHttpRequest();
      //   //建立连接
      //   xhr.open("post", "index.php/login/doLogin");
      //   //post方式必须的请求头
      //   xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");  
      //   //接收数据
      //   xhr.onreadystatechange=function() {
      //     if(xhr.readyState == 4 && xhr.status == 200) {
      //       var data = xhr.responseText;
      //       //var obj = eval('('+data+')');
      //       var obj = JSON.parse(data);
      //       console.log(obj);
      //       // console.log(obj.code);
      //       // console.log(obj.msg);
      //       //location.href = "/";
      //     } 
      //   };
      //   //发送数据
      //   xhr.send("username=" + username + "&password=" + password); 
      //   this.$vux.toast.text('您填写的密码不正确', 'middle');          
      // }


      // if (username != 110801010004 && password != "") {
      //   //创建对象
      //   var xhr = new XMLHttpRequest();
      //   //建立连接
      //   xhr.open("post", "index.php/login/doLogin");
      //   //post方式必须的请求头
      //   xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");  
      //   //接收数据
      //   xhr.onreadystatechange=function() {
      //     if(xhr.readyState == 4 && xhr.status == 200) {
      //       var data = xhr.responseText;
      //       //var obj = eval('('+data+')');
      //       var obj = JSON.parse(data);
      //       console.log(obj);
      //       // console.log(obj.code);
      //       // console.log(obj.msg);
      //       //location.href = "/";
      //     } 
      //   };
      //   //发送数据
      //   xhr.send("username=" + username + "&password=" + password); 
      //   this.$vux.toast.text('您填写用户不存在', 'middle');          
      // }




    }
  }
}
</script>
<style scoped>
  .logo-wrapper {
    text-align: center;
    margin: 80px 0
  }

  .logo {
    width: 100px;
    height: 100px
  }
</style>




<!-- xhr.onreadystatechange = callback;   
        xhr.send(); 
         function callback(){  
            if(xhr.readyState == 4){  
                if(xhr.status == 200){  
                    var friendsData = eval('('+xhr.responseText+')'); 
                     // console.log(friendsData.code);  
                     if(friendsData.code ==1001){
                        alert('用户名或密码不能为空')
                     }
                } else {  
                    alert(xhr.status);  
                }  
            }   
        }  -->